#include "junix.h"

char *program_name;
char *host=NULL;
char *service=NULL;

int main(int argc, char **argv)
{
	program_name = argv[0];

	if( argc != 3)
		err_quit("Usage:%s host service", program_name);

	host = argv[1];
	service = argv[2];

	int fd = connect_tcp(host, service);

	struct sockaddr sock;
	socklen_t len = sizeof(sock);
	if( getpeername( fd, &sock, &len) < 0 )
		err_sys("getpeername");

	char host_buf[1024];
	char service_buf[1024];

	if ( getnameinfo( &sock, len, 
				host_buf, sizeof(host_buf), service_buf, sizeof(service_buf), 0) )
		err_sys("getnmeinfo");

	printf("host:%s\n",host_buf);
	printf("service:%s\n",service_buf);

    exit(0);
}

